//
//  OilAccountVC.m
//  Base_App
//
//  Created by Yutian Duan on 2019/5/30.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "OilAccountVC.h"
#import "LoginVC.h"
#import "RegistVC.h"
#import "BaseNavigationVC.h"
#import "OilCardListTableView.h"


@interface OilAccountVC ()
///! 未登录
@property (nonatomic, strong) UIView *unLoginContentView;
///! 未绑定
@property (nonatomic, strong) UIView *unBindContentView;
///! 已绑定 TabbleView
@property (nonatomic, strong) OilCardListTableView *bindContentView;

@end

@implementation OilAccountVC

///! 未登录
- (UIView *)unLoginContentView {
  if (!_unLoginContentView) {
    _unLoginContentView = [[UIView alloc] initWithFrame:CGRectMake(0, 44, ScreenWidth, ScreenHeight - NavBarHeight - TabBarHeight - 34)];
    _unLoginContentView.backgroundColor = HEXCOLOR(0xf7f8fc);
    [self.view addSubview:_unLoginContentView];
    
    CGFloat logoTap = 100;
    if (IS_IPHONE5) {
      logoTap = 80;
    }
    
    //!
    UIImageView *logoImageView = [[UIImageView alloc] initWithFrame:CGRectMake((_unLoginContentView.yt_width-193)/2, logoTap, 193, 17)];
    logoImageView.image = [UIImage imageNamed:@"Oil_logo"];
    [_unLoginContentView addSubview:logoImageView];
    
    CGFloat fontSize = 18.0f;
    if (IS_IPHONE5) {
      fontSize = 15.0f;
    }
    
    ///!
    UILabel *remindLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, logoImageView.yt_bottom + 10, _unLoginContentView.yt_width - 80, 30)];
    remindLabel.textAlignment = NSTextAlignmentCenter;
    remindLabel.textColor = DEF_GRAY;
    remindLabel.text = YTLocalizedString(@"请登入以查阅已绑定之油咭咨询");
    remindLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize];
    [_unLoginContentView addSubview:remindLabel];
    
    ///! login
    UIButton *loginButton = [[UIButton alloc] initWithFrame:CGRectMake(_unLoginContentView.yt_width/2 - 86 - 20, remindLabel.yt_bottom + 40, 86, 33)];
//    [loginButton setImage:[UIImage imageNamed:@"Oil_Login"] forState:UIControlStateNormal];
  
    loginButton.backgroundColor = DEF_RED;
    loginButton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize];
    [loginButton setTitle:YTLocalizedString(@"登入") forState:UIControlStateNormal];
    [loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    loginButton.layer.masksToBounds = YES;
    loginButton.layer.cornerRadius = 10;
    
    [loginButton addTarget:self action:@selector(goLoginVC) forControlEvents:UIControlEventTouchUpInside];
    [_unLoginContentView addSubview:loginButton];
    
    
    ///
    UIButton *registButton = [[UIButton alloc] initWithFrame:CGRectMake(loginButton.yt_right + 40, loginButton.yt_top, loginButton.yt_width, loginButton.yt_height)];
//    [registButton setImage:[UIImage imageNamed:@"Oil_regist"] forState:UIControlStateNormal];
    
    registButton.backgroundColor = DEF_RED;
    registButton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize];
    [registButton setTitle:YTLocalizedString(@"注册") forState:UIControlStateNormal];
    [registButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    registButton.layer.masksToBounds = YES;
    registButton.layer.cornerRadius = 10;

    [registButton addTarget:self action:@selector(goRegistVC) forControlEvents:UIControlEventTouchUpInside];
    [_unLoginContentView addSubview:registButton];

    //!
    UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(registButton.yt_left - 10, registButton.yt_bottom + 10, registButton.yt_width + 20, 13)];
    tipLabel.text = [NSString stringWithFormat:@"%@？",YTLocalizedString(@"还没有成为HBC会员")];
    tipLabel.textColor = HEXCOLOR(0xbb2b25);
    tipLabel.font = [UIFont systemFontOfSize:10.0f];
    tipLabel.textAlignment = NSTextAlignmentCenter;
    [_unLoginContentView addSubview:tipLabel];
    
    //
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(_unLoginContentView.yt_centerX, loginButton.yt_top - 20, 0.8, loginButton.yt_height + 40)];
    lineView.backgroundColor = DEF_GRAY;
    [_unLoginContentView addSubview:lineView];
    
  }
  return _unLoginContentView;
}

///! 未绑定
- (UIView *)unBindContentView {
  if (!_unBindContentView) {
    _unBindContentView = [[UIView alloc] initWithFrame:CGRectMake(0, 44, ScreenWidth, ScreenHeight - NavBarHeight - TabBarHeight - 34)];
    _unBindContentView.backgroundColor = HEXCOLOR(0xf7f8fc);
    [self.view addSubview:_unBindContentView];

    
    CGFloat logoTap = 100;
    if (IS_IPHONE5) {
      logoTap = 80;
    }
    
    //!
    UIImageView *logoImageView = [[UIImageView alloc] initWithFrame:CGRectMake((_unBindContentView.yt_width-193)/2, logoTap, 193, 17)];
    logoImageView.image = [UIImage imageNamed:@"Oil_logo"];
    [_unBindContentView addSubview:logoImageView];
    
    CGFloat fontSize = 18.0f;
    if (IS_IPHONE5) {
      fontSize = 15.0f;
    }
    
    ///!
    UILabel *remindLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, logoImageView.yt_bottom + 10, _unBindContentView.yt_width - 80, 30)];
    remindLabel.textAlignment = NSTextAlignmentCenter;
    remindLabel.textColor = DEF_GRAY;
    remindLabel.text = YTLocalizedString(@"请先绑定油咭以查阅资讯");
    remindLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize];
    [_unBindContentView addSubview:remindLabel];


    
  }
  return _unBindContentView;
}

///! 已绑定
- (OilCardListTableView *)bindContentView {
  if (!_bindContentView) {
    ///!
    _bindContentView = [[OilCardListTableView alloc] initWithFrame:CGRectMake(0, 44, ScreenWidth, ScreenHeight - NavBarHeight - TabBarHeight - 34) style:UITableViewStylePlain];
    [self.view addSubview:_bindContentView];
    
    
    
  }
  return _bindContentView;
  
}

- (void)viewDidLoad {
  [super viewDidLoad];


}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  NSLog(@"我的户口");
}

- (void)createViews {
  [super createViews];
  
  
  
  
  
}


- (void)loadData {
  
  
  if ([ToolsServer sharedInstance].isLoginApp == YES) {
    ///! 已经登录
    if ([ToolsServer sharedInstance].isBindCard == YES) { //! 绑定
      _unLoginContentView.hidden = YES;
      _unBindContentView.hidden = YES;
      self.bindContentView.hidden = NO;
      
    } else {
      ///! 未绑定
      _unLoginContentView.hidden = YES;
      self.unBindContentView.hidden = NO;
      _bindContentView.hidden = YES;
    }
    
  } else {
    self.unLoginContentView.hidden = NO;
    _unBindContentView.hidden = YES;
    _bindContentView.hidden = YES;
    
  }
  
  
  
}



#pragma mark -
- (void)goLoginVC {
  LoginVC *new = [[LoginVC alloc] init];
  new.modalPresentationStyle = UIModalPresentationOverFullScreen;
  
  [self presentViewController:new
                     animated:YES
                   completion:^{
                     
                   }];

}

- (void)goRegistVC {
  
  
  RegistVC *registVC = [[RegistVC alloc] init];
  BaseNavigationVC *registNav = [[BaseNavigationVC alloc] initWithRootViewController:registVC];
  [self presentViewController:registNav animated:YES completion:nil];

  __weak typeof(self) weakSelf = self;
  ///! 注册成功弹出登录页面
  registVC.registSuccessed = ^{
    [weakSelf goLoginVC];
  };
  
  
}

@end

